package com.wjsh.common.base;

/**
 * Created by chenbaolin on 2017/8/10.
 */

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.trello.rxlifecycle2.components.support.RxFragment;
import com.wjsh.common.base.delegate.IFragment;
import com.wjsh.common.base.mvp.BasePresenter;

import javax.inject.Inject;

public abstract class BaseFragment<P extends BasePresenter> extends RxFragment implements IFragment {
    protected final String TAG = this.getClass().getSimpleName();

    @Inject
    protected P mPresenter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return initView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) mPresenter.onDestroy();
        this.mPresenter = null;
    }

    public BaseFragment() {
        //必须确保在Fragment实例化时setArguments()
        setArguments(new Bundle());
    }

    /**
     * 是否使用eventBus,默认为使用(true)，
     *
     * @return
     */
    @Override
    public boolean useEventBus() {
        return true;
    }
}
